Statistik 2

Hochschule Aalen

Sommersemester 2021

Martin Heckmann

martin.heckmann@hs-aalen.de

19.05.2021

Assignment 4: Parameter Estimation

Target

Target of the assignment is to understand the principles of parameter estimation.

Task 1

Task 2

Task 3

Package for linear regression

from sklearn.linear_model import LinearRegression

Package to calculate performance metrics

from sklearn import metrics

We init the model

lin_reg = LinearRegression()

We perform the fit by providing the X matrix and the y vector

Note: We do not need to prepend 1 to X as this is done internally

lin_reg.fit(X_train, y_train)

We print the coefficients (w0 = intercept, w_1 = linrg.coef)

print(linreg.intercept, linreg.coef)

Predict the test data

y_predict = lin_reg.predict(X_test)

Calculate the residuals, i.e. errors after fit

MSE = metrics.mean_squared_error(y_test, y_predict)

Drawing several histograms in one plot

bin_width = 1 fig = plotly.graph_objects.Figure() fig.add_trace(plotly.graph_objects.Histogram(x=data_frame[data_frame['size']==size1, name=size1,xbins=dict(size=bin_width))) fig.add_trace(plotly.graph_objects.Histogram(x=data_frame[data_frame['size']==size2, name=size2, xbins=dict(size=bin_width)))

fig.add_scatter(x=[population_value,population_value],y=[0, hist_height],name="population value")

fig.update_traces(opacity=0.75) fig.update_layout( title="MSE", barmode='overlay' ) fig.show()